<html>
<head>
	<title>添加</title>
</head>
<link rel="stylesheet" href="/js/layui/css/layui.css" />
<body>

<form class="layui-form"  action="" lay-filter="edit">
	<input type="text" name="id" id="id">
	<div class="layui-form-item">
		<label class="layui-form-label">工程师：</label>
		<div class="layui-col-xs8">
			<select name="mid" id="mid">
			</select>
		</div>
	</div>
	<div class="layui-form-item">
		<div class="layui-input-block">
			<button class="layui-btn" lay-submit lay-filter="formDemo">立即提交</button>
		</div>
	</div>
</form>
</body>

<script src="/js/jquery-3.2.1.js"></script>
<script src="/js/system.js"></script>
<script src="/js/layui/layui.js"></script>
<script>
	//Demo
	var param=window.parent.param;
	layui.use(['form','laydate','jquery'], function(){
		var form = layui.form
				,$ = layui.jquery;
		$.ajax({
			url:'/master/getList',
			type:"post",
			dataType:"json",
			success:function (da) {
				console.log(da);
				//请求工程师数据，所以后台没有使用jsondata 封装，直接返回的list集合
				$.each(da.data,function(i,obj){//new open()
					$("#mid").append("<option value='"+obj.id+"' maid='"+obj.maid+"'>"+obj.name +"</option>");
				});
				form.render();
				// form.val("edit",param);
				$("#id").val(param.id);
			}
		});

		//监听提交 15039939677
		form.on('submit(formDemo)', function(data){
			var id= $("#id").val();
			var sel= $("#mid option:selected");
			var mid= sel.val();
			var maid=sel.attr("maid");
			//alert(id+"   "+mid+"   "+maid+"   ");
			$.ajax({
				url:'/orders/sendMaster',
				type:"post",
				dataType:"json",
				data:{"id":id, "mid":mid, "maid":maid},
				success:function (da) {
					if (da.code == 200) {
						layer.alert(da.msg, function () {
							// window.parent.location.reload();//刷新父页面
							// parent.layer.close(layer.index);//关闭弹出层
							parent.layer.closeAll();
						});
					} else {
						layer.msg(da.msg);
					}
				}
			});
			return false;
		});
	});
</script>
</html>
